<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<br/>
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('index/shop/damagenum')}" method="get">
        <input type="hidden" name="id" value="{$id}"/>
        <input type="text" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res({$id})" value="全部显示" class="btn btn-default"/>
    </form>
</div>
<table class="table table-bordered" style="width: 1300px;margin: 0 auto">
    <tr>
        <th>商品名称</th>
        <th>购买数量</th>
        <th>损坏数量</th>
        <th>操作</th>
    </tr>
    {foreach $result as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <td>{$val.pname}</td>
        <td>{$val.number}</td>
        <td>{$val.num}</td>
        <td>
            <button onclick="num({$val.did})" type="button" class="btn btn-info btn-xs" >修改损坏数量</button>
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$result->render()}</div>
</body>
<script>
    //显示全部
    function res(id) {
        window.location.href = "{:url('index/shop/damagenum')}?id="+id;
    }

    //修改损坏数量
    function num(did) {
        layer.prompt({title: '修改损坏数量', formType: 2},
            function(number){
                $.ajax({
                    url:"{:url('/index/shop/updateNumber')}",
                    type:"post",
                    data: "did="+did+"&number="+number,
                    datatype:"json",
                    success:function(data){
                        if(data.success){
                            layer.alert(data.success,{btn:['确定','取消']},function () {
                                window.location.reload();
                            },function () {
                                window.location.reload();
                            });
                        }else{
                            layer.alert(data.error);
                        }
                    },
                });
            }
        );
    }
</script>
</html>